<template>
  <div>
    <a-layout>
      <a-layout>
        <div class="left">


          <a-layout-sider width="200" style="background: #fff">
            <p>项目架构</p>
            <p>XX集团</p>
            <el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
          </a-layout-sider>
        </div>
        <div class="right">
          <a-layout style="padding: 0 24px 24px">
            <div class="list1">
              <span class="span1">班组列表</span>
              <input type="button" value="新增" @click="classAdd" class="input1" />
            </div>
            <div class="list2">
              <span class="span2">搜索</span><input type="text" placeholder="请输入劳务班组名称/班组组长/联系方式" class="input2"
                v-model="firstone" />
              <span class="span2">状态</span>
              <el-select v-model="secondone" placeholder="---请选择---" class="input4" clearable>
                <el-option v-for="item in istatus" :key="item" :label="item" :value="item">
                </el-option>
              </el-select>
              <span class="span2">在场日期</span>
              <div class="block">

                <el-date-picker v-model="thirdone" type="date" placeholder="选择日期" style="width: 119px; height: 35px"
                  value-format="YYYY-MM-DD">
                </el-date-picker>
                <el-date-picker v-model="forone" type="date" placeholder="选择日期" style="width: 119px; height: 35px"
                  value-format="YYYY-MM-DD">
                </el-date-picker>
              </div>
              <input type="button" value="搜索" class="input3" @click="searchnature" />
            </div>
            <el-table :data="tableData.slice((page - 1) * limit, page * limit)" border style="width: 100%;">
              <el-table-column fixed type="index" label="序号" width="60" header-align="center" align="center">
                <template #default="scope">
                  <span>{{ (page - 1) * limit + scope.$index + 1 }}</span>
                </template>
              </el-table-column>
              <el-table-column prop="laowu" label="劳务班组" width="140">
              </el-table-column>
              <el-table-column prop="zuzhang" label="班组组长" width="80">
              </el-table-column>
              <el-table-column prop="card" label="组长证件" width="200">
              </el-table-column>
              <el-table-column prop="phone" label="联系方式" width="100">
              </el-table-column>
              <el-table-column prop="nums" label="班组人数" width="80">
              </el-table-column>
              <el-table-column prop="status" label="状态" width="80">
              </el-table-column>
              <el-table-column prop="enterdate" label="进场日期" width="100">
              </el-table-column>
              <el-table-column prop="godate" label="退场日期" width="100">
              </el-table-column>
              <el-table-column prop="caozuo" label="操作" width="160">
                <template #default="scope">
                  <el-button size="mini" @click="classEdit(scope.row.id)">编辑</el-button>
                  <el-popconfirm confirmButtonText="确定" cancelButtonText="取消" icon="el-icon-info" iconColor="red"
                    title="这是一条数据确定删除吗？" @confirm="confirmEvent(scope.row.id)" @cancel="cancelEvent">
                    <template #reference>
                      <el-button>删除</el-button>
                    </template>
                  </el-popconfirm>
                  <div>
                  </div>
                </template>
              </el-table-column>
            </el-table>
            <div class="list3">
              <!--分页组件-->
              <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page"
                :page-sizes="[4, 8, 12]" :page-size="limit" layout="total, sizes, prev, pager, next, jumper"
                :total="total">
              </el-pagination>
            </div>
          </a-layout>
        </div>
      </a-layout>
    </a-layout>
  </div>
  <classmangeadd v-show="isShowAdd" @hide="hideFn" @updatesuccess="successFn">
  </classmangeadd>
  <classmangedit v-show="isShowEdit" @hide="hideFn1" :id="editid" @updatesuccess="successFn1">
  </classmangedit>
</template>
<script setup lang="ts">
import { reactive, ref } from "vue";
import service from "../../../utils/service";
import classmangeadd from "./classmangeadd.vue";
import classmangedit from "./classmangedit.vue";
import { ElMessage } from "element-plus";



interface itabledata {
  id: string;
  laowu: string;
  zuzhang: string;
  card: string;
  phone: string;
  nums: string;
  status: string;
  enterdate: string;
  godate: string;
}
const page = ref(1)
const limit = ref(4)
const total = ref(0);

const tableData = reactive<itabledata[]>([]);
const tablestatus = reactive<{
  status?: string
  enterdate?: string
  godate?: string
}>({
});
const data = [
  {
    label: 'XXXXX建设有限公司',
    children: [
      {
        label: 'XXXX项目1',
        children: [
          {
            label: '中建八局',
            children: [
              {
                label: '中铁二建',

              },
            ],
          },
        ],
      },
      {
        label: 'XXXX项目2',
        children: [
          {
            label: '中建六局',
            children: [
              {
                label: '中铁四建',

              },
            ],
          },
        ],
      },
    ],
  },
]
const istatus = reactive(["---请选择---", "未进场", "进场", "已退场"])

// 获取数据列表
const gettableData = () => {
  service({
    url: "/classlist",
  }).then((res) => {
    tableData.length = 0;
    tableData.push(...res.data);
    total.value = res.data.length;

  });
};
gettableData();
// 分页
const handleSizeChange = (val: any) => {
  limit.value = val
}
const handleCurrentChange = (val: any) => {
  page.value = val
}
// 点击增加弹出框
const isShowAdd = ref(false); //控制修改组件的显示和隐藏
const classAdd = () => {
  isShowAdd.value = true;
};
const hideFn = () => {
  isShowAdd.value = false;
};
// 当修改成功后，需要重新发送请求，获取最新数据
const successFn = () => gettableData();

// 点击编辑弹出框
const isShowEdit = ref(false); //控制修改组件的显示和隐藏
const editid = ref("");
const classEdit = (id: string) => {
  editid.value = id;
  isShowEdit.value = true;
};
const hideFn1 = () => {
  isShowEdit.value = false;
};
// 当修改成功后，需要重新发送请求，获取最新数据
const successFn1 = () => gettableData();



// 删除单条数据
const confirmEvent = (id: string) => {
  service({
    url: "classlist/" + id,
    method: "delete",
  }).then((res) => {
    ElMessage({
      message: "删除单条数据成功！",
      type: "success",
    });

    gettableData();
  });
}
const cancelEvent = () => {
  console.log('confirm!')
}
const firstone = ref()
const secondone = ref()
const thirdone = ref()
const forone = ref()
// 点击搜索查看
const searchnature = () => {
  service({
    url: "/classlist?q=" + firstone.value,
    method: "get",
    params: {
      "status": secondone.value,
      "enterdate": thirdone.value,
      "godate": forone.value
    }

  }).then((res) => {
    firstone.value = "";
    secondone.value = undefined;
    thirdone.value = undefined;
    forone.value = undefined;
    console.log(res);
    tableData.length = 0;
    tableData.push(...res.data);

  });

} 
</script>
<style scoped>
#components-layout-demo-top-side-2 .logo {
  float: left;
  width: 120px;
  height: 31px;
  margin: 16px 24px 16px 0;
  background: rgba(255, 255, 255, 0.3);
}

.ant-row-rtl #components-layout-demo-top-side-2 .logo {
  float: right;
  margin: 16px 0 16px 24px;
}

.site-layout-background {
  background: #fff;
}

.left {
  width: 220px;
  height: 709px;
  background: #fff;
  /* border: 1px solid #999; */
}

.right {
  /* width: 1164.67px; */
  height: 709px;
  background: #fff;
  margin-left: 10px;
  /* border: 1px solid #999; */
}

p {
  color: #666;
}

.list1 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
}

.list2 {
  margin-top: 10px;
  position: relative;
}

.block {
  position: absolute;
  top: 0;
  left: 585px;

}

.input1 {
  width: 72px;
  height: 30px;
  background: inherit;
  background-color: #FF9900;
  box-sizing: border-box;
  border-width: 1px;
  border-style: solid;
  border-color: #FF9900;
  border-radius: 5px;
  -moz-box-shadow: none;
  -webkit-box-shadow: none;
  box-shadow: none;
  font-family: "PingFangSC-Regular", "PingFang SC";
  font-weight: 400;
  font-style: normal;
  font-size: 12px;
  color: #FFF;
}

.span1 {
  font-weight: 700;
  font-style: normal;
  font-size: 16px;
  color: #666;
}

.span2 {

  font-size: 12px;
  color: #666;
  margin-left: 10px;
}

.input2 {
  width: 232px;
  height: 27px;
  font-weight: 400;
  font-style: normal;
  font-size: 12px;
  text-align: center;
  margin-left: 20px;
  border: 1px solid #999;
}

.input3 {
  width: 71px;
  height: 35px;
  background: inherit;
  background-color: rgba(59, 177, 156, 1);
  box-sizing: border-box;
  border-width: 1px;
  border-style: solid;
  border-color: rgba(26, 188, 156, 1);
  border-radius: 5px;
  font-weight: 400;
  font-style: normal;
  font-size: 12px;
  color: #ffffff;
  margin-left: 280px;
}

.input4 {
  width: 177px;
  height: 35px;
  background-color: rgba(255, 255, 255, 0);
  /* box-sizing: border-box; */
  border: 1px solid #999;
  border-radius: 3px;
  margin-left: 10px;
}

.el-table--fit {
  margin-top: 10px;
}

.cell {
  font-size: 12px;
  color: #666;
  font-weight: 600;
  text-align: center;
}

.span3 {
  width: 40px;
  height: 22px;
  line-height: 22px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.988235294117647);
  background: #999999;
  border-radius: 5px;
  text-align: center;
}

.span4 {
  width: 60px;
  height: 22px;
  line-height: 22px;
  text-align: center;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.988235294117647);
  background-color: rgba(153, 153, 153, 1);
  border-radius: 5px;
}

.span5 {
  width: 114px;
  height: 20px;
  font-size: 12px;
  color: rgb(102, 102, 102);
  margin-left: 10px;
}

.list3 {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-top: 15px;
}
</style>
